package com.yuzhyn.hiops.app.application.controller.sys;

import com.alibaba.fastjson.JSON;
import com.yuzhyn.azylee.websdk.args.WebSdk;
import com.yuzhyn.hiops.common.entity.Tables;
import com.yuzhyn.hiops.common.mapper.DbMapper;
import com.yuzhyn.hiops.app.application.service.IdService;
import com.yuzhyn.hiops.common.model.ResponseData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping({"i/id"})
public class IdController {

    @Autowired
    IdService idService;

    @Autowired
    DbMapper dbMapper;

    @GetMapping("/uuid")
    public String uuid() {
        return idService.getId();
    }

    @GetMapping("/tables")
    public String tables() {
        List<Tables> tables = dbMapper.getTables();
        return JSON.toJSONString(tables);
    }

    @GetMapping("/snow")
    public String snow() throws Exception {
//        throw new Exception("");
        return String.valueOf(WebSdk.SnowFlake.nexts());
    }

    @PostMapping("/ex")
    public ResponseData ex() throws Exception {
        throw new Exception("报错了");
    }

//    @GetMapping("/get/{count}")
//    public ResponseData get(@PathVariable("count") int count) {
//        ArrayList<Long> ids = new ArrayList();
//        SnowflakeTool idWorker = new SnowflakeTool(1, 1, 1);
//        if (count <= 0) {
//            count = 1;
//        }
//        for (int i = 0; i < count; i++) {
//            ids.add(idWorker.nexts());
//        }
//        return ResponseData.ok(ids);
//    }
}
